package com.ojoin.trade.t0loan_core.web.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.web.dao.impl.BaseDaoImpl;
import com.ojoin.trade.t0loan_core.web.dao.TbIntentUserDao;
import com.ojoin.trade.t0loan_core.web.domain.TbIntentUser;

@Repository
public class TbIntentUserDaoImpl extends BaseDaoImpl<TbIntentUser> implements TbIntentUserDao {

	public SqlSession getSqlSession() {
		return this.sqlSessionTemplate;
	}
	
	@Override
	public int updateContactFlagByID(int[] ids, String memo, String contactflag) throws BusinessException {
		String mapMethodName = "updateContactFlagByID";
		
		try {
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("ids", ids);
			paramMap.put("memo", memo);
			paramMap.put("contactflag", contactflag);
			
			return getSqlSession().update(getSqlName(mapMethodName), paramMap);
		} catch (Exception e) {
			throw new DaoException(String.format("根据ids和loanstatus更新意向商户状态出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
	}

	@Override
	public List<TbIntentUser> queryIntentUserListByContactflag(String contactflag)
			throws BusinessException {
		String mapMethodName = "queryIntentUserListByContactflag";
		try {
			List list = this.sqlSessionTemplate.selectList(getSqlName(mapMethodName),
					contactflag);
			if (list != null && list.size() >0)
				return list;
		} catch (Exception e) {
			throw new DaoException(String.format("查询contactflag：" + contactflag + "的意向商户列表出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
		
		return null;
	}

}
